package com.meixiang.entity.shopping;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.meixiang.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 购物车商品
 *
 * @author LZRUI
 */
public class CartGoodsEntity implements Parcelable {

    private String isGroup; // 是否是组合商品（Y/N）
    private String goodsNum; // 商品数量
    private String firstGcId; // 购物车规格id
    private String cartId; // 购物车id
    private String goodsId; // 商品id
    private String goodsName; // 商品名称
    private String goodsStorePrice; // 店铺价格
    private String goodsMarketPrice; // 市场价格
    private String goodsImage; // 图片
    private String goodsSpecId; // 商品
    private String specGoodsPrice;//  商品规格价格
    private List<String> specInfo; // 商品规格信息
    private List<CartGroupEntity> goodsGroupList; // 组合套装
    private boolean isSelected; //  是否选中

    public CartGoodsEntity(String isGroup, String goodsNum, String firstGcId, String cartId, String goodsId, String goodsName, String goodsStorePrice, String goodsMarketPrice, String goodsImage, String goodsSpecId, String specGoodsPrice, List<String> specInfo, List<CartGroupEntity> goodsGroupList) {
        this.isGroup = isGroup;
        this.goodsNum = goodsNum;
        this.firstGcId = firstGcId;
        this.cartId = cartId;
        this.goodsId = goodsId;
        this.goodsName = goodsName;
        this.goodsStorePrice = goodsStorePrice;
        this.goodsMarketPrice = goodsMarketPrice;
        this.goodsImage = goodsImage;
        this.goodsSpecId = goodsSpecId;
        this.specGoodsPrice = specGoodsPrice;
        this.specInfo = specInfo;
        this.goodsGroupList = goodsGroupList;
    }

    public CartGoodsEntity() {
    }

    public String getGoodsNum() {
        return goodsNum == null ? "0" : goodsNum.trim();
    }

    public void setGoodsNum(String goodsNum) {
        this.goodsNum = goodsNum;
    }

    public String getFirstGcId() {
        return firstGcId == null ? "" : firstGcId;
    }

    public void setFirstGcId(String firstGcId) {
        this.firstGcId = firstGcId;
    }

    public String getCartId() {
        return cartId == null ? "" : cartId;
    }

    public void setCartId(String cartId) {
        this.cartId = cartId;
    }

    public String getGoodsId() {
        return goodsId == null ? "" : goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public String getGoodsName() {
        return goodsName == null ? "" : goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getGoodsStorePrice() {
        return goodsStorePrice == null ? "0.00" : goodsStorePrice;
    }

    public void setGoodsStorePrice(String goodsStorePrice) {
        this.goodsStorePrice = goodsStorePrice;
    }

    public String getGoodsMarketPrice() {
        return goodsMarketPrice == null ? "0.00" : goodsMarketPrice;
    }

    public void setGoodsMarketPrice(String goodsMarketPrice) {
        this.goodsMarketPrice = goodsMarketPrice;
    }

    public String getGoodsImage() {
        return goodsImage == null ? "" : goodsImage;
    }

    public void setGoodsImage(String goodsImage) {
        this.goodsImage = goodsImage;
    }

    public String getGoodsSpecId() {
        return goodsSpecId == null ? "" : goodsSpecId;
    }

    public void setGoodsSpecId(String goodsSpecId) {
        this.goodsSpecId = goodsSpecId;
    }

    public String getSpecGoodsPrice() {
        return specGoodsPrice == null ? "0.00" : specGoodsPrice;
    }

    public void setSpecGoodsPrice(String specGoodsPrice) {
        this.specGoodsPrice = specGoodsPrice;
    }

    public List<String> getSpecInfo() {
        return specInfo;
    }

    public void setSpecInfo(List<String> specInfo) {
        this.specInfo = specInfo;
    }

    public String getIsGroup() {
        return isGroup;
    }

    public void setIsGroup(String isGroup) {
        this.isGroup = isGroup;
    }

    public List<CartGroupEntity> getGoodsGroupList() {
        return goodsGroupList;
    }

    public void setGoodsGroupList(List<CartGroupEntity> goodsGroupList) {
        this.goodsGroupList = goodsGroupList;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    /**
     * 拼接specInfo字符串
     *
     * @return string
     */
    public String getSpecInfoString(Context context) {
        String info = "";
        int len = this.specInfo == null ? 0 : this.specInfo.size();
        for (int i = 0; i < len; i++) {
            info += this.specInfo.get(i);
            if (i != len - 1) {
                info += context.getString(R.string.space_str);
            }
        }
        return info;
    }

    /**
     * 判断是否是组合类型
     *
     * @return
     */
    public boolean isGroup() {
        if (!TextUtils.isEmpty(isGroup) && isGroup.trim().equals("Y")) {
            return true;
        }
        return false;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.isGroup);
        dest.writeString(this.goodsNum);
        dest.writeString(this.firstGcId);
        dest.writeString(this.cartId);
        dest.writeString(this.goodsId);
        dest.writeString(this.goodsName);
        dest.writeString(this.goodsStorePrice);
        dest.writeString(this.goodsMarketPrice);
        dest.writeString(this.goodsImage);
        dest.writeString(this.goodsSpecId);
        dest.writeString(this.specGoodsPrice);
        dest.writeStringList(this.specInfo);
        dest.writeList(this.goodsGroupList);
        dest.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
    }

    protected CartGoodsEntity(Parcel in) {
        this.isGroup = in.readString();
        this.goodsNum = in.readString();
        this.firstGcId = in.readString();
        this.cartId = in.readString();
        this.goodsId = in.readString();
        this.goodsName = in.readString();
        this.goodsStorePrice = in.readString();
        this.goodsMarketPrice = in.readString();
        this.goodsImage = in.readString();
        this.goodsSpecId = in.readString();
        this.specGoodsPrice = in.readString();
        this.specInfo = in.createStringArrayList();
        this.goodsGroupList = new ArrayList<CartGroupEntity>();
        in.readList(this.goodsGroupList, CartGroupEntity.class.getClassLoader());
        this.isSelected = in.readByte() != 0;
    }

    public static final Parcelable.Creator<CartGoodsEntity> CREATOR = new Parcelable.Creator<CartGoodsEntity>() {
        @Override
        public CartGoodsEntity createFromParcel(Parcel source) {
            return new CartGoodsEntity(source);
        }

        @Override
        public CartGoodsEntity[] newArray(int size) {
            return new CartGoodsEntity[size];
        }
    };
}
